﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace X.LOG
{
    public static class LogStashHelper
    {
        internal async static void PostLog(string server, int serverPort, object obj)
        {
            var url = new Uri($"{server}:{serverPort}");
            var postData = Common.Serialize(obj);
            await Task.Run(() =>
            {
                using (var client = new WebClient())
                {
                    client.Encoding = Encoding.UTF8;
                    client.Headers.Add("Content-Type", "application/json");
                    client.UploadDataAsync(url, "POST", Encoding.UTF8.GetBytes(postData));
                }
            });
        }
    }
}
